﻿<UserControl x:Class="Manas.DynamicDeepZoom.CodeCamp.LevelsControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:core="clr-namespace:Manas.DynamicDeepZoom.Core;assembly=Manas.DynamicDeepZoom.Core"
    xmlns:ic="clr-namespace:Manas.DynamicDeepZoom.CodeCamp.ItemControls"
    >

    <UserControl.Resources>

        <core:LevelDefiner x:Key="CurrentLevelDefiner" />

        <DataTemplate x:Key="NullTemplate">
            <Rectangle Visibility="Hidden" />
        </DataTemplate>

        <!-- Description Level -->
        <DataTemplate x:Key="DescriptionLevelTemplate">
            <ic:Description />
        </DataTemplate>

        <core:LevelTemplateSelector x:Key="DescriptionLevelSelector"
            ChildrenTemplate="{StaticResource NullTemplate}"
            LevelTemplate="{StaticResource DescriptionLevelTemplate}" 
            Level="12" LevelDefiner="{StaticResource CurrentLevelDefiner}"  />

        <DataTemplate x:Key="TalkChildren">
            <ItemsControl ItemsSource="{Binding Children}" ItemTemplateSelector="{StaticResource DescriptionLevelSelector}">
                <ItemsControl.ItemContainerStyleSelector>
                    <core:LevelContainerStyleSelector Level="12" ContainerHeight="512" ContainerWidth="512" LevelDefiner="{StaticResource CurrentLevelDefiner}" />
                </ItemsControl.ItemContainerStyleSelector>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </DataTemplate>

        <!-- Talk level -->
        <DataTemplate x:Key="TalkLevelTemplate">
            <ic:Talk />
        </DataTemplate>

        <core:LevelTemplateSelector x:Key="TalkLevelSelector"
            ChildrenTemplate="{StaticResource TalkChildren}"
            LevelTemplate="{StaticResource TalkLevelTemplate}" 
            Level="11" LevelDefiner="{StaticResource CurrentLevelDefiner}"  />

        <DataTemplate x:Key="TimeChildren">
            <ItemsControl ItemsSource="{Binding Children}" ItemTemplateSelector="{StaticResource TalkLevelSelector}">
                <ItemsControl.ItemContainerStyleSelector>
                    <core:LevelContainerStyleSelector Level="11" ContainerHeight="256" ContainerWidth="256" LevelDefiner="{StaticResource CurrentLevelDefiner}" />
                </ItemsControl.ItemContainerStyleSelector>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </DataTemplate>

        <!-- Time of day level -->
        <DataTemplate x:Key="TimeLevelTemplate">
            <ic:TimeOfDay />
        </DataTemplate>

        <core:LevelTemplateSelector x:Key="TimeLevelSelector"
            ChildrenTemplate="{StaticResource TimeChildren}" 
            LevelTemplate="{StaticResource TimeLevelTemplate}" 
            Level="9" LevelDefiner="{StaticResource CurrentLevelDefiner}"  />

        <DataTemplate x:Key="CodecampLevelTemplate">
            <ic:Codecamp />
        </DataTemplate>

        <DataTemplate x:Key="CodecampChildren">
            <ItemsControl ItemsSource="{Binding Children}" ItemTemplateSelector="{StaticResource TimeLevelSelector}">
                <ItemsControl.ItemContainerStyleSelector>
                    <core:LevelContainerStyleSelector Level="9" ContainerHeight="256" ContainerWidth="256" 
                                                      LevelDefiner="{StaticResource CurrentLevelDefiner}" />
                </ItemsControl.ItemContainerStyleSelector>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </DataTemplate>

        <!-- Codecamp level -->
        <core:LevelTemplateSelector x:Key="CodecampLevelSelector" 
            ChildrenTemplate="{StaticResource CodecampChildren}" 
            LevelTemplate="{StaticResource CodecampLevelTemplate}" 
            FromLevel="3" Level="8" LevelDefiner="{StaticResource CurrentLevelDefiner}"/>
    
    </UserControl.Resources>

    <Grid>
        
        <ContentControl ContentTemplateSelector="{StaticResource CodecampLevelSelector}"
                        Content="{Binding Path=Model}" />
    
    </Grid>
</UserControl>
